package com.sixth.service.impl;

import com.sixth.dao.AclRoleDao;
import com.sixth.entity.AclRole;
import com.sixth.service.RoleService;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: self-tui-education
 * @description:
 * @author: 高振杨
 * @create: 2022-04-22 15:34
 **/
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private AclRoleDao roleDao;
    @Override
    public CommonResult addOrUpdateRole(AclRole role) {

        String roleName = role.getRoleName();
        String remark = role.getRemark();
        String id2 = role.getId();
        String code = role.getRoleCode();
        Date date = new Date();
        if (id2==null||id2==""){
            role.setGmtCreate(date);
            Date gmtCreate = role.getGmtCreate();
            role.setGmtModified(date);
            Date gmtModified = role.getGmtModified();
            role.setIsDeleted(0);

            Integer isDeleted = role.getIsDeleted();
            role.setRoleCode("1");
            String roleCode = role.getRoleCode();

            int i= roleDao.selectcount();
            int id = i+1;
            role.setId(id+"");
            String id1 = role.getId();
            int j =roleDao.addORole(id1,roleName,roleCode,remark,isDeleted,gmtCreate,gmtModified);
            if (j>0){
                return new CommonResult(2000,"添加成功",null);
            }
            return new CommonResult(5000,"添加失败",null);
        }

        int i =roleDao.updateORole(id2,remark,roleName,date,code);
        if (i>0){
            return new CommonResult(2000,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    @Override
    public CommonResult deleteRoleById(String roleid) {
        int i=roleDao.deleteRoleById(roleid);
        if (i>0){
            return new CommonResult(2000,"删除成功",null);
        }
        return new CommonResult(5000,"删除失败",null);
    }
}
